program Procedures;

{$APPTYPE CONSOLE}

uses
  SysUtils;

type
  pelement = ^element;
  element = record
    value: integer;
    next: pelement;
  end;

var
  head: pelement;
  fin: textFile;
  num, n, i: integer;


procedure Add (var head: pelement; num: integer);
  var tmp: pelement;
  begin
    tmp:= head;
    new (head);
    head^.next:= tmp;
    head^.value:= num;
  end;

function Delete (var head: pelement): integer;
  var tmp: pelement;
  begin
    tmp:= head^.next;
    Delete:= head^.value;
    dispose (head);
    head:= tmp;
  end;

procedure PrintList (head: pelement);
  var current: pelement;
  begin
    current:= head;
    while (current<>nil) do
    begin
      writeln (current^.value);
      current:= current^.next;
    end;
  end;


function DeleteEnd (var head: pelement): integer;
  var current: pelement;
  begin
    if (head<>nil) then
    begin
      current:=head;
      while (current^.next <> nil) do
      begin
        current:= current^.next;
      end;
      DeleteEnd:= current^.value;
      current:= nil;
    end;
  end;

begin
  assignFile (fin, 'input.txt');
  reset (fin);
  readln (fin, n);
  for i:= 1 to n do
    begin
      readln (fin, num);
      Add (head, num);
    end;
  PrintList (head);
  writeln (DeleteEnd (head));
  closeFile(fin);
  readln;
end.
